﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;


public partial class Comment : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }


    }
    /// <summary>
    /// 用来给GridView绑定数据
    /// 我不知道数据库里的字段名，自己起了个名字
    /// ID是留言的编号，留言日期，留言内容对应相应字段
    /// 表取名comment
    /// 连接字符串我取的是web.config里面的字段
    /// 到时候只要在<connectionStrings/>里面设置就好
    /// </summary>
    protected void BindData()
    {
        SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        string str = "select * from comment";
        SqlDataAdapter da = new SqlDataAdapter(str, sqlcon);
        DataSet ds = new DataSet();
        sqlcon.Open();
        da.Fill(ds, "comment");
        GridView.DataSource = ds;
        GridView.DataKeyNames = new string[] { "CommentId" };
        GridView.DataBind();
        sqlcon.Close();
    }
    /// <summary>
    /// GridView分页响应函数
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView.PageIndex = e.NewPageIndex;
        BindData();
    }
    /// <summary>
    /// 提交留言相应函数
    /// 和上面一样字段名和表名是我自己起的
    /// 留言内容我限定为500字符
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void BnIsert_Click(object sender, EventArgs e)
    {
        if (TextBox.Text.Length > 500)
        {
            Response.Write("<script language=javascript>alert('字符数不能超过500！');</script>");
        }
        else
        {
            string str = "insert into comment (Comment_Data,Comment_content) values('" + DateTime.Now.ToString() + "','" + TextBox.Text + "')";
            SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            SqlCommand sqlcom = new SqlCommand(str, sqlcon);
            sqlcon.Open();
            sqlcom.ExecuteNonQuery();
            sqlcon.Close();
        }
    }
    /// <summary>
    /// 下拉内容改变相应函数
    /// 用于改变文本框内字体大小
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void DropFont_SelectedIndexChanged(object sender, EventArgs e)
    {
        //TextBox.Font.Size = DropFont.SelectedItem.Value;
    }
}